package com.cloud.pay.constant;

import com.cloud.common.context.AppContext;
import com.cloud.pay.payment.AliPayAdapter;
import com.cloud.pay.payment.PayAdapter;
import com.cloud.pay.payment.WxPayAdapter;
import lombok.Getter;

public enum PayChannelEnum {

    WECHAT_PAY(1, AppContext.getBean(WxPayAdapter.class)),
    ALI_PAY(2, AppContext.getBean(AliPayAdapter.class));

    @Getter
    private int code;

    @Getter
    private PayAdapter payAdapter;

    PayChannelEnum(int code, PayAdapter payAdapter) {
        this.code = code;
        this.payAdapter = payAdapter;
    }

    public static PayChannelEnum of(int code) {
        for (PayChannelEnum payChannelEnum : values()) {
            if (payChannelEnum.code == code) {
                return payChannelEnum;
            }
        }
        return null;
    }
}
